package map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapDemo2 {
    public static void main(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("语文",96);
        map.put("数学",97);
        map.put("英语",91);
        map.put("物理",88);
        map.put("化学",88);
        System.out.println(map);

        /**
         * 遍历键
         */
        System.out.println("遍历键------------------");
        /*Set<String> keySet = map.keySet();
        for(String key : keySet){
            System.out.println("key:"+key);
        }*/
        Set<String> keySet = map.keySet();
        for(String key : keySet){
            System.out.println("key"+key);
        }



        /**
         * 遍历键值
         */
        System.out.println("遍历键值------------------");
        /*Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        for(Map.Entry<String,Integer> m :entrySet){
            String key = m.getKey();
            Integer value = m.getValue();
            System.out.println(key+"："+value);
        }*/
        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        for(Map.Entry<String,Integer> m: entrySet){
            String key = m.getKey();
            Integer value = m.getValue();
            System.out.println(key+":"+value);


        }

        System.out.println("Lambda------------------");
        map.forEach((k,v)-> System.out.println(k+":"+v));

        /**
         * 遍历值
         */
        System.out.println("遍历值------------------");
        /*Collection<Integer> values = map.values();
        for(Integer value : values){
            System.out.println("value:"+value);
        }*/
        Collection<Integer> values = map.values();
        for(Integer value : values){
            System.out.println(value);
        }


        System.out.println("Lambda------------------");
        //values.forEach(e-> System.out.println(e));
        /*values.forEach(System.out::println);*/
        /*values.forEach(e-> System.out.println(e));*/
        values.forEach(System.out::println);

        map.forEach((k,v)->System.out.println(k+":"+v));
    }
}
